by Davis Chapman
In This Chapter
When you are building an application using Winsock functionality, you have to know and work with more than just the basic network communications. You also need to know and work with the appropriate protocol for the application that you are writing. An application protocol is the conversation that takes place between the client application and the server with which it is exchanging messages. This conversation is usually a series of commands issued by the client (and occasionally by the server) to which the server responds. These commands have to be formatted in a specific way, and often have to follow a specific order.
With the prevalence of the Web in computing now, Microsoft decided to ease the burden of incorporating Web functionality into any Windows applications. As a result of this decision, Microsoft introduced the Windows Internet (WinInet for short) extensions to the Windows API. By encapsulating the primary Web protocols as extensions to the Windows API, Microsoft has greatly simplified the process of Web- and Internet-enabling just about any application.
When the Web first began, few Web sites were actually running the Hypertext Transfer Protocol (HTTP) upon which the Web is based. Instead, what you had was a mixture of sites running mostly the File Transfer Protocol (FTP) and the Gopher protocols. Both of these application protocols were able to deliver the basic HTML Web pages to a browser, so all were in fairly equal use. It has only been through the passage of time, and the explosive growth of the Web, that the FTP and Gopher protocols have fallen out of use, as almost all sites are now running HTTP servers for their Web sites. Because of these origins, Web browsers started out having to support all three of these Internet application protocols. With the effort to Internet-enable other applications, it has been assumed that all three of these protocols would need to be supported.
The Hypertext Transfer Protocol started out as one of the simplest Internet application protocols. When the Web first started to become popular, the HTTP protocol consisted of three basic commands, GET, POST, and HEAD. These three commands performed the basic functions of the Web. The GET command would request a specific object from the Web server, such as an HTML page or image file, and the Web server would respond by sending the object through the same socket connection. The HEAD command would cause the Web server to respond with what was basically a description of the object that had been requested, like the type of file the object was (HTML, image, and so on), its size, and when it was last updated. The final command, POST, would be used to send data to the Web server, which would usually pass this information along to a separate application to process and generate some dynamic output to be returned to the Web browser.
Along with a small set of commands that could be issued to the Web server, the HTTP protocol was also a single-command-per-connection protocol. In other words, a Web browser would connect to a Web server, send one of these three commands, receive the response, and close the connection. If a Web page contained three images, the Web browser would make at least four connections to the Web server: one for the Web page and one for each of the three images.
Since those early beginnings, the HTTP protocol has undergone several changes. It now consists of several commands, including commands that can be used to place Web pages and other objects onto the Web server, and can keep the connection open for multiple commands. Along with all the changes in the way commands are sent and responded to, the HTTP protocol has also added requirements on how the commands and responses are formatted. All in all, there have been many changes in the HTTP protocol, and there will probably be more to come.
The File Transfer Protocol is a bit more involved and has been around for quite a while longer than the HTTP protocol. FTP is used for moving files between two or more computers, regardless of the type of computers involved. It provides the client application with the capability of moving around in the servers file system, getting files from and placing files onto the server wherever the client has permission to do so. If the user has appropriate permissions on the FTP server, the user can even delete files from the server using the FTP protocol.
Because of the more extensive requirements of the FTP protocol, it is quite a bit different from the HTTP protocol. First, the client application has to log in to the FTP server, providing a username and password before access is granted to the client application. Second, the FTP protocol has an extensive set of commands for navigating through the servers file system; getting directory listings; and moving, deleting, and renaming files, along with the basic file transfer commands to move files from the client computer to the server and vice versa.
A third aspect of the FTP protocol is that it uses more than one socket connection to perform its tasks. A single socket connection is opened by the client that remains open until the session is completed. This is known as the command connection. A second socket connection is opened either by the server or the client that is used to move any data between the two computers, as in Figure 25.1. This second connection is used to pass files between the two computers. It is also used to send directory listings from the server to the client. This connection is opened each time the client issues a command to the server that involves any data being passed between the two computers, and is closed when all of the data has been passed for that one command.
Figure 25.1 The FTP protocol uses two socket connections.
The Gopher protocol is somewhere in between the FTP and HTTP protocols in terms of functionality and complexity. It can be used like the FTP protocol to browse server file systems, and to retrieve files from the server. It can also be used to search multiple servers for files on a particular subject. The Gopher protocol was originally developed as a document search and delivery mechanism, very much the same purpose for which the HTTP protocol was developed (and around the same time, too). The differences between the Gopher and HTTP protocols are that the Gopher protocol was originally more involved, containing much of the file system navigation functionality from the FTP protocol, and the HTTP protocol was tightly coupled with the Hypertext Markup Language (HTML) format for document presentation. It was because the HTTP/HTML combination lent itself to graphical displaysmore than the Gopher protocol didthat the HTTP/HTML combination became the dominant protocol for the Web.
Note:The Gopher protocol is one of the few Internet application protocols whose name is not an acronym for a functional description of the protocol. The Gopher protocol was developed at the University of Minnesota, Minnesota being known as the Gopher state. As a result, the Gopher protocol took its name from where it was developed, not from what it does.